package Algorithm.ReviewCode;

public class ReverseLinkedList {

    public static ListNode reverseList(ListNode head){

        if (head == null) {
            return null;
        }

        ListNode cur = head,prev = null;
        while (cur != null) {
            ListNode tmp = cur.next;
            cur.next = prev;
            prev = cur;
            cur = tmp;
        }
        return prev;
    }


    public static void main(String[] args) {
        int[] a = new int[]{1,2,3,4,2,5};
        ListNode listNode = new ListNode(a);
        System.out.println(listNode);
        ListNode listNode1 = reverseList(listNode);
        System.out.println(listNode1);

    }

}
